% A function to rename files in a directory
function move_files_to_parent(parent_dir)
%parent_dir = 'C:\Documents and Settings\conrabp\My Documents\Research\Sahajpal\AC Joint Project\Analysis';
ext = '*.xls';

all_data_dir = dir(parent_dir);
for i =3:length(all_data_dir)
    disp(['processing : ', all_data_dir(i).name]);
    subject_data_dir=dir(fullfile(parent_dir,all_data_dir(i).name, ext)); 
    for j=1:length(subject_data_dir)
        old_name = fullfile(parent_dir,all_data_dir(i).name, subject_data_dir(j).name);
        new_name = fullfile(parent_dir,[all_data_dir(i).name, '_', subject_data_dir(j).name]);
        disp(['    ',all_data_dir(i).name, '_', subject_data_dir(j).name]);
        copyfile(old_name,new_name);
    end
end

disp('Done!')